/*
	File: data/scripts/scene_spawn-physics-instances.nut
	Author: GameStart3d.com
*/

/*!
	@short	SceneSpawnPhysicsInstances
	@author	GameStart3d.com
*/
class	SceneSpawnPhysicsInstances
{

	item_spawn_position		=	0
	spawn_position			=	0

	timer					=	0.0

	instance_path			=	"data/assets/instance_crate_physics.nms"

	function	OnSetup(scene)
	{
		item_spawn_position = SceneFindItem(scene, "spawn_position")
		timer = 0.0
	}

	function	OnUpdate(scene)
	{
		local	dt_frame = 1.0 / 60.0
		spawn_position = ItemGetWorldPosition(item_spawn_position)

		timer += dt_frame

		if (timer > 2.0)
		{
			print("SceneSpawnPhysicsInstances::OnUpdate() Spawn!")
			SceneSpawnNewItem(scene)
			timer = 0.0
		}
	}
	
	function	OnRenderUser(scene)
	{
		RendererDrawCross(g_render, spawn_position)
	}

	function	SceneSpawnNewItem(scene)
	{
		//	
		local	_group = SceneLoadAndStoreGroup(scene, instance_path, ImportFlagObject)
//		GroupSetup(_group)	//	Question 1 : is this needed ?
		GroupRenderSetup(_group, g_factory)

		//	Question 2 : how to set the position of the group/instance that was just loaded ?
//		local	_item = GroupGetItemList(_group)[0]	//Picking a random item from its list, is this the correct way ?

//		ItemSetPosition(_item, spawn_position)
		//	Question 3 : this binding below usually works. Should I use ItemSetPhysicPosition/Rotation() instead ?
//		ItemPhysicResetTransformation(_item, spawn_position, Vector())
//		ItemWake(_item)
	}

}
